﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var persianDateTime = new PersianDateTime(new DateTime(2013, 4, 9));
            var expected = new PersianDateTime(1392, 1, 20);

            Assert.AreEqual(expected, persianDateTime, "test failed");
        }

        [TestMethod]
        public void TestMethod2()
        {
            var persianDateTime = new PersianDateTime(new DateTime(2013, 4, 11));
            var expected = PersianDateTime.Parse("1392/01/22");

            Assert.AreEqual(expected, persianDateTime, "test failed");
        }

        [TestMethod]
        public void TestMethod3()
        {
            var persianDateTime = new PersianDateTime(1392, 1, 20);
            var expected = new PersianDateTime(13920120);

            Assert.AreEqual(expected, persianDateTime, "test failed");
        }

        [TestMethod]
        public void TestMethod4()
        {
            var persianDateTime = new PersianDateTime(1392, 1, 20);

            Assert.AreEqual(1392, persianDateTime.Year, "test failed");
            Assert.AreEqual(1, persianDateTime.Month, "test failed");
            Assert.AreEqual(20, persianDateTime.Day, "test failed");
        }

        [TestMethod]
        public void TestMethod5()
        {
            Assert.AreEqual(30, PersianDateTime.GetDaysInMonth(1391, 12), "test failed");
            Assert.AreEqual(29, PersianDateTime.GetDaysInMonth(1392, 12), "test failed");
            Assert.AreEqual(31, PersianDateTime.GetDaysInMonth(1392, 1), "test failed");
            Assert.AreEqual(30, PersianDateTime.GetDaysInMonth(1392, 7), "test failed");
        }

        [TestMethod]
        public void TestMethod6()
        {
            var persianDateTime1 = new PersianDateTime(1392, 2, 20);
            var persianDateTime2 = new PersianDateTime(1392, 1, 3);

            Assert.AreEqual(TimeSpan.FromDays(48), persianDateTime1 - persianDateTime2, "test failed");
            Assert.AreEqual(persianDateTime2, persianDateTime1 - TimeSpan.FromDays(48), "test failed");
            Assert.AreEqual(persianDateTime1, persianDateTime2 + TimeSpan.FromDays(48), "test failed");
            Assert.AreEqual(true, persianDateTime1 > persianDateTime2, "test failed");
            Assert.AreEqual(false, persianDateTime1 < persianDateTime2, "test failed");
            Assert.AreEqual(true, persianDateTime1 >= persianDateTime2, "test failed");
            Assert.AreEqual(false, persianDateTime1 <= persianDateTime2, "test failed");
            Assert.AreEqual(false, persianDateTime1 == persianDateTime2, "test failed");
            Assert.AreEqual(true, persianDateTime1 != persianDateTime2, "test failed");
        }

        [TestMethod]
        public void TestMethod7()
        {
            var persianDateTime1 = new PersianDateTime(1392, 12, 29);
            var persianDateTime2 = new PersianDateTime(1393, 1, 1);

            Assert.AreEqual(persianDateTime2, persianDateTime1.AddDays(1), "test failed");
            Assert.AreEqual(persianDateTime2, persianDateTime1.AddHours(24), "test failed");
        }

        [TestMethod]
        public void TestMethod8()
        {
            var persianDateTime = new PersianDateTime(1392, 05, 31);

            Assert.AreEqual(persianDateTime.AddYears(-4), new PersianDateTime(1388, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(-3), new PersianDateTime(1389, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(-2), new PersianDateTime(1390, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(-1), new PersianDateTime(1391, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(0), new PersianDateTime(1392, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(1), new PersianDateTime(1393, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(2), new PersianDateTime(1394, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(3), new PersianDateTime(1395, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddYears(4), new PersianDateTime(1396, 05, 31), "test failed");
        }

        [TestMethod]
        public void TestMethod9()
        {
            var persianDateTime = new PersianDateTime(1392, 05, 31);

            Assert.AreEqual(persianDateTime.AddMonths(1), new PersianDateTime(1392, 06, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(2), new PersianDateTime(1392, 07, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(3), new PersianDateTime(1392, 08, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(4), new PersianDateTime(1392, 09, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(5), new PersianDateTime(1392, 10, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(6), new PersianDateTime(1392, 11, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(7), new PersianDateTime(1392, 12, 29), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(8), new PersianDateTime(1393, 01, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(9), new PersianDateTime(1393, 02, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(10), new PersianDateTime(1393, 03, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(11), new PersianDateTime(1393, 04, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(12), new PersianDateTime(1393, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(13), new PersianDateTime(1393, 06, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(14), new PersianDateTime(1393, 07, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(15), new PersianDateTime(1393, 08, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(16), new PersianDateTime(1393, 09, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(17), new PersianDateTime(1393, 10, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(18), new PersianDateTime(1393, 11, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(19), new PersianDateTime(1393, 12, 29), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(20), new PersianDateTime(1394, 01, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(21), new PersianDateTime(1394, 02, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(22), new PersianDateTime(1394, 03, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(23), new PersianDateTime(1394, 04, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(24), new PersianDateTime(1394, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(25), new PersianDateTime(1394, 06, 31), "test failed");

            Assert.AreEqual(persianDateTime.AddMonths(0), new PersianDateTime(1392, 05, 31), "test failed");

            Assert.AreEqual(persianDateTime.AddMonths(-1), new PersianDateTime(1392, 04, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-2), new PersianDateTime(1392, 03, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-3), new PersianDateTime(1392, 02, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-4), new PersianDateTime(1392, 01, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-5), new PersianDateTime(1391, 12, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-6), new PersianDateTime(1391, 11, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-7), new PersianDateTime(1391, 10, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-8), new PersianDateTime(1391, 09, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-9), new PersianDateTime(1391, 08, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-10), new PersianDateTime(1391, 07, 30), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-11), new PersianDateTime(1391, 06, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-12), new PersianDateTime(1391, 05, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-13), new PersianDateTime(1391, 04, 31), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-17), new PersianDateTime(1390, 12, 29), "test failed");
            Assert.AreEqual(persianDateTime.AddMonths(-20), new PersianDateTime(1390, 09, 30), "test failed");
        }

        [TestMethod]
        public void TestMethod10()
        {
            var dateTime = DateTime.Now;
            var persianDateTime = new PersianDateTime(dateTime);

            Assert.AreEqual(persianDateTime.TimeOfDay, dateTime.TimeOfDay, "test failed");
            Assert.AreEqual(persianDateTime.Hour, dateTime.Hour, "test failed");
            Assert.AreEqual(persianDateTime.Minute, dateTime.Minute, "test failed");
            Assert.AreEqual(persianDateTime.Second, dateTime.Second, "test failed");
            Assert.AreEqual(persianDateTime.Millisecond, dateTime.Millisecond, "test failed");
            Assert.AreEqual(persianDateTime.Ticks, dateTime.Ticks, "test failed");
        }

        [TestMethod]
        public void TestMethod11()
        {
            var persianDateTime = new PersianDateTime(1392, 1, 7);
            var firstDayOfMonth = new PersianDateTime(1392, 1, 1);
            var lastDayOfMonth = new PersianDateTime(1392, 1, 31);

            Assert.AreEqual(firstDayOfMonth, persianDateTime.FirstDayOfMonth, "test failed");
            Assert.AreEqual(firstDayOfMonth, persianDateTime.FirstDayOfYear, "test failed");
            Assert.AreEqual(lastDayOfMonth, persianDateTime.LastDayOfMonth, "test failed");
        }

        [TestMethod]
        public void TestMethod12()
        {
            var persianDateTime = new PersianDateTime(1392, 2, 20);

            Assert.AreEqual(6, persianDateTime.DayOfWeek, "test failed");
            Assert.AreEqual(31, persianDateTime.DaysInMonth, "test failed");
            Assert.AreEqual(51, persianDateTime.DayOfYear, "test failed");
        }

        [TestMethod]
        public void TestMethod13()
        {
            var persianDateTime1 = new PersianDateTime(1392, 1, 3);
            var persianDateTime2 = new PersianDateTime(1392, 1, 3);

            Assert.AreEqual(true, persianDateTime1 != null, "test failed");
            Assert.AreEqual(false, persianDateTime1 == null, "test failed");
            Assert.AreEqual(true, null != persianDateTime1, "test failed");
            Assert.AreEqual(false, null == persianDateTime1, "test failed");
            Assert.AreEqual(true, persianDateTime1 == persianDateTime2, "test failed");
            Assert.AreEqual(false, persianDateTime1 != persianDateTime2, "test failed");
        }
    }
}
